package com.mashiro.system.service;

import com.mashiro.system.domain.MoeFund;

import java.util.List;

/**
 * 资金Service接口
 *
 * @author mashiro
 * @date 2023-04-15
 */
public interface IMoeFundService {
    /**
     * 查询资金
     *
     * @param id 资金主键
     * @return 资金
     */
    public MoeFund selectMoeFundById(Long id);

    /**
     * 查询资金列表
     *
     * @param moeFund 资金
     * @return 资金集合
     */
    public List<MoeFund> selectMoeFundList(MoeFund moeFund);

    /**
     * 新增资金
     *
     * @param moeFund 资金
     * @return 结果
     */
    public int insertMoeFund(MoeFund moeFund);

    /**
     * 修改资金
     *
     * @param moeFund 资金
     * @return 结果
     */
    public int updateMoeFund(MoeFund moeFund);

    /**
     * 批量删除资金
     *
     * @param ids 需要删除的资金主键集合
     * @return 结果
     */
    public int deleteMoeFundByIds(Long[] ids);

    /**
     * 删除资金信息
     *
     * @param id 资金主键
     * @return 结果
     */
    public int deleteMoeFundById(Long id);

    /**
     * 是否存在资金子节点
     *
     * @param id 资金ID
     * @return 结果
     */
    public boolean hasChildByFundId(Long id);

    /**
     * 是否存在资金子节点
     *
     * @param projectId 项目ID
     * @param taskId 任务ID
     * @return 结果
     */
    public MoeFund getFundInfo(Long projectId, Long taskId);
    /**
     * 计算项目已使用资金情况
     *
     * @param projectId 项目ID
     * @return 结果
     */
    public MoeFund getProjectUsedFunding(Long projectId);

    /**
     * 查询资金列表
     *
     * @param ids 项目经理
     * @return 资金集合
     */
    public List<MoeFund> getMoeFundListByProjectIds(MoeFund moeFund, Long[] ids);



    public default Long getTotalFunding(MoeFund moeFund) {
        Long total = 0L;
        if (moeFund.getProvinceFunding() != null) {
            total += moeFund.getProvinceFunding();
        }
        if (moeFund.getCityFunding() != null) {
            total += moeFund.getCityFunding();
        }
        if (moeFund.getCompanyFunding() != null) {
            total += moeFund.getCompanyFunding();
        }
        return total;
    }

    public default Long getUsedFunding(MoeFund moeFund) {
        Long total = 0L;
        if (moeFund.getUsedProvinceFunding() != null) {
            total += moeFund.getUsedProvinceFunding();
        }
        if (moeFund.getUsedCityFunding() != null) {
            total += moeFund.getUsedCityFunding();
        }
        if (moeFund.getUsedCompanyFunding() != null) {
            total += moeFund.getUsedCompanyFunding();
        }
        return total;
    }
}
